﻿using System.IO;
using System.Reflection;
using Abp;
using Abp.PlugIns;
using Abp.Reflection.Extensions;
using Castle.Facilities.Logging;
using Castle.Windsor.MsDependencyInjection;
using Hengyuantong.SmartRail.Identity;
using Microsoft.Extensions.DependencyInjection;
using Castle.Facilities.Logging;
//using Castle.Services.Logging.NLogIntegration;
using Topshelf;
using Abp.Castle.Logging.Log4Net;

namespace Hengyuantong.SmartRail.Services
{
    public class Program
    {
        protected Program()
        {
        }
        static void Main(string[] args)
        {
            //string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var currentDirectory = typeof(Program).GetAssembly().GetDirectoryPathOrNull();
            Directory.SetCurrentDirectory(currentDirectory);

            using (var bootstrapper = AbpBootstrapper.Create<HengyuantongServicesModule>())
            {
                bootstrapper.IocManager.IocContainer.AddFacility<LoggingFacility>(f => f.UseAbpLog4Net().WithConfig("log4net.config"));
                bootstrapper.Initialize();

                HostFactory.Run(x =>
                {
                    x.Service<ServiceRunner>();
                    x.RunAsLocalSystem();

                    x.SetServiceName("Longfor.Risk.Services");
                    x.SetDisplayName("SmartRail调度服务");
                    x.SetDescription("SmartRail调度服务");

                    x.StartAutomatically();
                    x.EnablePauseAndContinue();
                });
            }
        }
    }
}
